﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeJC.DAL.Model;

namespace DeJC.BLL.Managers {
    public static class CountryManager {
        public static IEnumerable<Country> GetCountrys() {
            IEnumerable<Country> countrys;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                countrys=unitOfWork.CountryRepository.GetAll();
            }
            return countrys;
        }

        public static List<Country> GetCountries() {
            List<Country> countrys;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                countrys= new List<Country>(unitOfWork.CountryRepository.GetAll());
            }
            return countrys;
        }

        public static bool AddCountry(Country country) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                unitOfWork.CountryRepository.Add(country);
                unitOfWork.Save();
            }
            return true;
        }

        // public bool UpdateCountry(Country country, int id)
        // {
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // var countryEntity = unitOfWork.CountryRepository.GetById(id);
        // countryEntity.Title = country.Title;
        // countryEntity.FirstName = country.FirstName;
        // countryEntity.LastName = country.LastName;
        // countryEntity.ModifiedDate = DateTime.Now;
        // unitOfWork.Save();
        // }
        // return true;
        // }

        public static bool DeleteCountry(int id) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                Country country=unitOfWork.CountryRepository.GetById(id);
                unitOfWork.CountryRepository.Delete(country);
                unitOfWork.Save();
            }
            return true;
        }

        // public List<Country> GetCountryPaged(int page, int rows, out int totalCount)
        // {
        // List<Country> countrys;
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // countrys = unitOfWork.CountryRepository.GetCountryPaged
        // (page, rows, out totalCount);
        // }
        // return countrys;
        // }
        public static Country GetById(int id) {
            Country country;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                country=unitOfWork.CountryRepository.GetById(id);
            }
            return country;
        }
    }
}
